<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width= , initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <script>
        var arr = [9, 3, 6, 2, 4, 1, 8, 5, 7]
        console.log(arr);
        for (var j = 0; j < arr.length - 1; j++) {

            var minIndex = j;
            for (var i = j+1; i < arr.length; i++) {
                if (arr[i] < arr[minIndex]) {
                    minIndex = i;
                }
            }
            var temp = arr[j]
            arr[j] = arr[minIndex]
            arr[minIndex] = temp
        }
        console.log(arr);
    </script>

</body>

</html>